package com.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import com.bean.Locality;
import com.dao.CountryDao;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.util.LoggerUtil;
@Component("countryDao")
public class CountryDaoImpl implements CountryDao{
	public static Logger logger=Logger.getLogger(CountryDaoImpl.class);
	@Autowired
	private MongoTemplate mongoTemplate;
	@Override
	public Map<String, Object> selectTagByArea(String areaId,JSONObject logs){
		Map<String, Object> map=new HashMap<String, Object>();
		
		try {
			Locality locality=mongoTemplate.findById(areaId, Locality.class);
			if(locality!=null){
				String tag[]=locality.getTags();
				
				if(tag!=null&&tag.length>0){
					map.put("result", "success");
					map.put("rows", tag);
					LoggerUtil.backlogsSuccess(logs, logger);
					return map;
				}
			}
			map.put("result", "false");
			LoggerUtil.backlogsFalseNOData(logs, logger);
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}
	@Override
	public List<Locality> selectHotCity(){
		DBObject dbObject = new BasicDBObject();
		dbObject.put("isHot", true);
		DBObject fieldObject = new BasicDBObject();
		fieldObject.put("zhName", true);
		fieldObject.put("_id", true);
		Query query = new BasicQuery(dbObject, fieldObject);
		List<Locality> hotCities=mongoTemplate.find(query, Locality.class);
		return hotCities;
	}
}
